import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

class Test_login():
    def setup_method(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get("http://127.0.0.1/index.php/Home/user/login.html")

    #正确的用户名和密码
    def test01_login(self):
        self.driver.find_element(By.ID, 'username').send_keys('18325539630')
        self.driver.find_element(By.ID, 'password').send_keys('wsf123456')
        self.driver.find_element(By.ID, 'verify_code').send_keys('8888')
        self.driver.find_element(By.NAME, 'sbtbutton').click()
        phone = WebDriverWait(self.driver, 9, 1).until(lambda
            x: x.find_element(By.CLASS_NAME, 'mu-m-phone')).text

        #断言
        assert phone == '18325539630'

    #账号格式不匹配
    def test02_login(self):
        self.driver.find_element(By.ID, 'username').send_keys('183255396')
        self.driver.find_element(By.ID, 'password').send_keys('wsf123456')
        self.driver.find_element(By.ID, 'verify_code').send_keys('8888')
        self.driver.find_element(By.NAME, 'sbtbutton').click()
        message = WebDriverWait(self.driver, 9, 1).until(lambda
         x: x.find_element(By.CLASS_NAME, 'layui-layer-content')).text

        #断言
        assert message == '账号格式不匹配!'

    #正确的用户名和错误的密码
    def test03_login(self):
        self.driver.find_element(By.ID, 'username').send_keys('18325539630')
        self.driver.find_element(By.ID, 'password').send_keys('ws')
        self.driver.find_element(By.ID, 'verify_code').send_keys('8888')
        self.driver.find_element(By.NAME, 'sbtbutton').click()
        message = WebDriverWait(self.driver, 9, 1).until(lambda
         x: x.find_element(By.CLASS_NAME, 'layui-layer-content')).text

        #断言
        assert message == '密码错误!'

    #账号不存在
    def test04_login(self):
        self.driver.find_element(By.ID, 'username').send_keys('18325539631')
        self.driver.find_element(By.ID, 'password').send_keys('wsf123456')
        self.driver.find_element(By.ID, 'verify_code').send_keys('8888')
        self.driver.find_element(By.NAME, 'sbtbutton').click()
        message = WebDriverWait(self.driver, 9, 1).until(lambda
        x: x.find_element(By.CLASS_NAME, 'layui-layer-content')).text

        #断言
        assert message == '账号不存在!'

    # def tearDown_method(self):
    #     self.driver.quit()